<?php

namespace App\Repositories\Eloquent\Edu;

use Illuminate\Container\Container as App;
use App\Repositories\Eloquent\Repository;

use App\Repositories\Eloquent\Mgt\UserRepository as User;

class TypeRepository extends Repository
{

    protected $user;

    public function __construct(App $app, User $user)
    {
        parent::__construct($app);

        $this->user = $user;
    }

    /**
     * 指定模型名称
     *
     * @return mixed
     */
    function model()
    {
        return 'App\Models\Edu\Type';
    }


    /**
     * loader 延迟预加载参数
     * @param  [type] $loader [description]
     * @return [type]         [description]
     */
    public function index($loader = null)
    {
        if(isset($loader)){
            $result = $this->model
                ->where('status', STATUS_NORMAL)
                ->orderBy('id', 'asc')
                ->get();
        }
        else{
            $result = $this->model
                ->orderBy('id', 'asc')
                ->get();
        }

        //if(isset($loader)){
            $result->load(
                'terms',
                'terms.categories',
                'terms.clases',
                'terms.users',
                'terms.branch',
                'terms.admits');
        //}

        return $result;
    }


    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store($request, $pid)
    {


    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $type = $this->find($id);

        if (!$type) {
            return $this->responseFail(404);
        }

        return $type;
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function renew($request, $id)
    {
        if( $request->status == -1){
            $result = $this->delete($id);
        }
        else{
            $result = $this->update([
                'status' => $request->status,
            ], $id);
        }


        if(!!$result)
            return $this->responseSuccess('操作成功', $request->status);

        return $this->responseFail(500,'操作失败');
    }



    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }


}